package com.cqeec.bootdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cqeec.bootdemo.Service.EmployeeService;
import com.cqeec.bootdemo.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @PostMapping("/getList")
    public List<Employee> getAll(){
       return employeeService.list();
    }
    @GetMapping("/getById/{username}")
    public Employee getById(@PathVariable("username") String username){
        //实体化条件构造器
        LambdaQueryWrapper<Employee> wrapper=new LambdaQueryWrapper<>();
        //添加查询条件(字段名，值) username= username
        wrapper.eq(Employee::getUsername,username);
        Employee employee= employeeService.getOne(wrapper);
        return employee;
    }
    //查询表中sex=1的所有数据
    @GetMapping("/getListBySex")
    public List<Employee> getListBySex(){
        LambdaQueryWrapper<Employee> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Employee::getSex,1);
        employeeService.list(wrapper);
        return employeeService.list(wrapper);
    }
    //查询电话中有23的所有数据
    @GetMapping("getListPhone")
    public List<Employee> getListPhone(){
        LambdaQueryWrapper<Employee> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(Employee::getPhone,"237");
        employeeService.list(wrapper);
        return employeeService.list(wrapper);
    }
    @GetMapping("/getListByNumber")
    public List<Employee> getListByNumber(){
        LambdaQueryWrapper<Employee> wrapper=new LambdaQueryWrapper<>();
//        wrapper.gt(Employee::getIdNumber,"500");
        wrapper.orderByAsc(Employee::getId).like(Employee::getIdNumber,"101");
//如果还有其他的条件，方法名（字段，值）
        return employeeService.list(wrapper);
    }
}
